from typing import Any, Optional

from fastapi import HTTPException
from pydantic import BaseModel


class CommonResponse(BaseModel):
    code: int
    msg: str
    data: Optional[Any] = None


def success_response(data: Any = None, message: str = "Success") -> CommonResponse:
    return CommonResponse(code=200, msg=message, data=data)


def error_response(status_code: int, message: str, detail: Optional[Any] = None) -> HTTPException:
    raise HTTPException(code=status_code, msg=detail, headers={"Content-Type": "application/json"})


def failure_response(status_code: int, message: str, detail: Optional[Any] = None) -> CommonResponse:
    return CommonResponse(code=status_code, msg=message, data=detail)
